<template>
	<view class="smart-page">
		<view class="smart-page-head">
			<view class="smart-page-head-title">Switch 开关</view>
		</view>
		
		<view class="smart-padding-wrap">
			<!-- 默认样式 -->
			<view class="section">
				<view class="section-title">默认样式</view>
				<view class="card">
					<view class="switch-item">
						<text class="label">开启状态</text>
						<switch checked @change="switch1Change" class="custom-switch"></switch>
					</view>
					<view class="switch-item">
						<text class="label">关闭状态</text>
						<switch @change="switch2Change" class="custom-switch"></switch>
					</view>
				</view>
			</view>

			<!-- 自定义样式 -->
			<view class="section">
				<view class="section-title">自定义颜色</view>
				<view class="card">
					<view class="switch-item">
						<text class="label">金色主题</text>
						<switch checked color="#FFCC33" @change="switch1Change" class="custom-switch"></switch>
					</view>
					<view class="switch-item">
						<text class="label">金色主题</text>
						<switch color="#FFCC33" @change="switch2Change" class="custom-switch"></switch>
					</view>
				</view>
			</view>

			<!-- 多彩主题 -->
			<view class="section">
				<view class="section-title">多彩主题</view>
				<view class="card">
					<view class="switch-item" v-for="(item, index) in themeSwitches" :key="index">
						<text class="label">{{item.label}}</text>
						<switch :checked="item.checked" :color="item.color" 
								@change="handleThemeSwitchChange(index)"
								class="custom-switch"></switch>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				themeSwitches: [
					{ label: '蓝色主题', color: '#007AFF', checked: true },
					{ label: '绿色主题', color: '#4CD964', checked: false },
					{ label: '橙色主题', color: '#FF9500', checked: true },
					{ label: '紫色主题', color: '#5856D6', checked: false }
				]
			}
		},
		methods: {
			switch1Change: function(e) {
				console.log('switch1 发生 change 事件，携带值为', e.detail.value);
			},
			switch2Change: function (e) {
				console.log('switch2 发生 change 事件，携带值为', e.detail.value);
			},
			handleThemeSwitchChange(index) {
				this.themeSwitches[index].checked = !this.themeSwitches[index].checked;
				console.log(`主题开关${index + 1} 状态:`, this.themeSwitches[index].checked);
			}
		}
	}
</script>

<style>
	.smart-page {
		background: #f5f7fa;
		min-height: 100vh;
		padding: 30rpx;
	}
	
	.smart-page-head {
		text-align: center;
		margin-bottom: 40rpx;
		padding: 30rpx 0;
	}
	
	.smart-page-head-title {
		font-size: 40rpx;
		font-weight: 600;
		color: #2c3e50;
	}
	
	.section {
		margin-bottom: 40rpx;
	}
	
	.section-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #2c3e50;
		margin-bottom: 20rpx;
		padding-left: 10rpx;
	}
	
	.card {
		background: #ffffff;
		border-radius: 16rpx;
		padding: 30rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
	}
	
	.switch-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 25rpx 0;
		border-bottom: 1rpx solid #f1f2f6;
	}
	
	.switch-item:last-child {
		border-bottom: none;
	}
	
	.label {
		font-size: 30rpx;
		color: #2c3e50;
		font-weight: 500;
	}
	
	.custom-switch {
		transform: scale(1.1);
	}
	
	/* 响应式设计 */
	@media (max-width: 750rpx) {
		.smart-page {
			padding: 20rpx;
		}
		
		.card {
			padding: 20rpx;
		}
	}
</style>